#ifndef _RPC_CLIENT_H_
#define _RPC_CLIENT_H_

#ifdef __cplusplus
extern "C"{
#endif

extern int  	MaxCcNum;
extern int 	CPU_TICK_PER_SEC;
//total 12 bytes
typedef struct _RPC_HEAD_CLIENT_{
	unsigned int version:8;
    	unsigned int pkt_type:8;
    	unsigned int pkt_len:16;

    	unsigned int resv;

    	unsigned int rpc_id:16;
    	unsigned int param_num:16;
}RPC_HEAD_CLIENT_ST;


typedef struct _RPC_PARAM_CLIENT_{
    	unsigned int type:16;
    	unsigned int length:16;
    	unsigned int value[0];
}RPC_PARAM_CLIENT_ST;

enum RPC_TYPE_CLIENT{
    	TypeClientInvalid,
    	TypeClientI8,
    	TypeClientI16,
    	TypeClientI32,
    	TypeClientI64,
    	TypeClientU8, 
    	TypeClientU16,
    	TypeClientU32,
    	TypeClientU64,
    	TypeClientDouble,
    	TypeClientString
};

#define RPC_REQUEST 				1
#define RPC_RESPONSE 				2
#define DEVICE_OF_NETWORK                "eth0"
#define RPC_REQUEST_LNGTH  		4096 

#define RPC_SERV_PORT 				3369

#define MAX_CC_NUM 					8
#define taskDelay(a)					usleep(a * 100)	

#if 0
#define RPC_DEBUG
#endif
#ifdef RPC_DEBUG
#define RPCDebugOut(fmt, args...) printf(fmt,##args);
#else
#define RPCDebugOut(fmt, args...)
#endif

//store all of the ips
extern char 	g_cc_ipaddr_list[MAX_CC_NUM][32];
extern int 	init_flag;
extern void 	cli_rpc_generate_head(unsigned char *request, int pkt_len, int rpc_id, int param_num);
extern void 	cli_rpc_generate_param(unsigned char *request, int *offset, int *pkt_len, int type, int len, unsigned char *value);
extern int 	readCCResponse(int fd,unsigned char *response);
extern void 	cli_rpc_parse_param(unsigned char *response, int *offset, unsigned char *result);
extern int 	cliRpcWrite(int sockfd,char *data , int len);
extern void SetDefalutTick();
extern void cc_ipaddr_list_init();
extern int   get_cc_ipaddr_list();
/*
 * macro of generating parameter.
 *
 * type	: type of parameter,such as TypeClientU32,TypeClientI32 etc.
 * len	: total length of parameter, including fields 'type & length' 
 *      		in structure RPC_PARAM_CLIENT_ST.
 * param	: parameter to generate
 *
 * Tsihang 16/08/2012
 */

#define CLI_RPC_GENERATE_PARAM(type, len, param)\
    do{\
        cli_rpc_generate_param(request, &offset, &pkt_len, type, len, (unsigned char*)&param);\
        param_num++;\
      }while(0)

#define CLI_RPC_GENERATE_PARAM_POINTER(type, len, param)\
    do{\
        cli_rpc_generate_param(request, &offset, &pkt_len, type, len, (unsigned char*)param);\
        param_num++;\
      }while(0)
#ifdef __cplusplus
}
#endif
#endif
